<template>
  <div class="login-container">
    <div class="login-box">
      <h1>智能体小梦斗破苍穹问答系统</h1>
      <form @submit.prevent="handleSubmit">
        <div class="form-group">
          <label>账号：</label>
          <input
            type="text" 
            v-model="username"
            placeholder="请输入账号"
            class="input-field"
          />
        </div>
        <div class="form-group">
          <label>密码：</label>
          <input
            type="password"
            v-model="password"
            placeholder="请输入密码"
            class="input-field"
          />
        </div>
        <button type="submit" class="login-btn">进入斗破世界</button>
        <div v-if="errorMsg" class="error-msg">{{ errorMsg }}</div>
      </form>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const username = ref('')
const password = ref('')
const errorMsg = ref('')

const handleSubmit = () => {
  if (username.value === 'xmdpcq' && password.value === 'xmdpcq') {
    localStorage.setItem('isAuthenticated', 'true')
    router.push('/chat')
  } else {
    errorMsg.value = '萧炎提示：阁下输入的账号或密码有误，请重试！'
    password.value = ''
  }
}
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: url('@/assets/login.jpg') no-repeat center center fixed;
  background-size: cover;
}

.login-box {
  background: transparent;
  padding: 2rem 3rem;
  border-radius: 15px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
  width: 400px;
}

h1 {
  text-align: center;
  color: white;
  margin-bottom: 1.5rem;
  font-size: 24px;
  font-family: 'Microsoft YaHei', sans-serif;
  text-shadow: 1px 1px 2px #000;
}

.form-group {
  margin-bottom: 1.5rem;
}

label {
  margin-bottom: 0.5rem;
  color: white;
  font-weight: bold;
  text-shadow: 1px 1px 2px #000;
  display: block;
}

.input-field {
  width: 100%;
  padding: 0.8rem;
  border: 2px solid #fff;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.3s;
  background-color: transparent;
  color: white;
}

.input-field:focus {
  outline: none;
  border-color: #3498db;
}

.login-btn {
  width: 100%;
  padding: 1rem;
  background-color: #e74c3c;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.3s;
  text-transform: uppercase;
  font-weight: bold;
}

.login-btn:hover {
  background-color: #c0392b;
}

.error-msg {
  color: #e74c3c;
  margin-top: 1rem;
  text-align: center;
  font-weight: bold;
  animation: shake 0.5s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}
</style>